<template>
  <div
    class="request-party-service-manage-body"
    style="margin-right: 10px"
  >
    <el-checkbox v-model="checked" @change="checkedCha">查询本级及下级</el-checkbox>

    <el-tree
      :props="props"
      :load="loadNode"
      lazy
      @node-click="getCurrentNode"
    />
  </div>
</template>

<script>
import { getRootRegionsV1, getChildrenRegionsListByNumV2 } from '@/api/groupCameraSynchronization'

export default {
  name: 'GroupTree',
  data() {
    return {
      checked: true,
      value: null,
      props: {
        label: 'name',
        value: 'indexCode',
        isLeaf: 'leaf'
      }
    }
  },
  methods: {
    checkedCha(val) {
      this.$emit('checkedCha', val)
    },
    getCurrentNode(data) {
      this.$emit('changeIndexCode', data.indexCode)
    },
    async loadNode(node, resolve) {
      if (node.level === 0) {
        const { data } = await getRootRegionsV1()
        resolve([data])
        this.$emit('rootNode', data.indexCode)
      } else {
        const { data } = await getChildrenRegionsListByNumV2({ parentIndexCode: node.data.indexCode, resourceType: 'camera' })
        resolve(data.list)
      }
    }
  }
}
</script>
